/**
 * 项目名：phms3
 * 日期：    2019-12-01 17:02:29
 * Copyright (c) 2015- HTSC-版权所有
 */

package com.joysuch.wwyt.bp.repository;

import java.util.List;

import com.joysuch.wwyt.bp.entity.BpDeviceFacilityMonitoringPoint;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

/**
 * BpDeviceFacilityMonitoringPointDao
 */
public interface BpDeviceFacilityMonitoringPointDao extends JpaRepository<BpDeviceFacilityMonitoringPoint, Long>,
        QuerydslPredicateExecutor<BpDeviceFacilityMonitoringPoint> {

    public Page<BpDeviceFacilityMonitoringPoint> findAll(Specification<BpDeviceFacilityMonitoringPoint> spec,
            Pageable pageable);

    public BpDeviceFacilityMonitoringPoint save(BpDeviceFacilityMonitoringPoint bean);

    public void delete(BpDeviceFacilityMonitoringPoint bean);

    public void deleteByDeviceId(Long deviceId);

    @Query("select count(*) from BpDeviceFacilityMonitoringPoint where deviceId=?1")
    public Long findBindMonitoringPointCountOfDevice(Long id);

    public BpDeviceFacilityMonitoringPoint findFirstByMonitoringPointId(Long monitorPointId);

    void deleteByMonitoringPointId(Long monitoringPointId);

    public void deleteByDeviceIdAndMonitoringPointId(Long id, Long monitorPointId);

    List<BpDeviceFacilityMonitoringPoint> findByDeviceId(Long id);

    @Query(value = "SELECT DISTINCT MONITORING_POINT_ID FROM wwyt_bp_device_facility_monitoring_point WHERE DEVICE_ID = ?1 AND DELETE_FLAG = '0' ", nativeQuery = true)
    List<Long> getMonitoringPointIdsByDeviceId(Long deviceId);

    @Query(value = "SELECT DISTINCT p.pointCode FROM BpDeviceFacilityMonitoringPoint f,MhMonitoringPoint p WHERE f.monitoringPointId=p.id and f.deviceId=?1 ")
    List<String> getMonitoringPointCodesByDeviceId(Long deviceId);

    @Query(value = "SELECT DISTINCT DEVICE_ID FROM wwyt_bp_device_facility_monitoring_point WHERE DELETE_FLAG = '0' ", nativeQuery = true)
    List<Long> findAllDeviceId();

}
